// pages/mine/mine.ts

import Varible from "../../constants/index";


Page({
  data: {
    avatarUrl: '/pages/assets/zly21.jpeg', // 头像地址
    userName: '王*颜',
    userAddress: '月亮湾小区服务站',
    onlineTime: '您已累计在线 60 小时',
    walletAmount: 300,
    orderCount: 4
  },
  goToWallet: function () {
    wx.navigateTo({
      url: '/pages/wallet/wallet'
    });
  },
  toUserinfo() {
    wx.navigateTo({
      url: '/pages/userinfo/userinfo'
    })
  },
  async changeAvatar() {
    // 弹出相册/拍照选择器
    const result =  await wx.chooseMedia({
      count: 1,
      mediaType: ['image']
    })
    if (result.tempFiles.length) {
      this.setData({
        avatarUrl: result.tempFiles[0].tempFilePath
      })
    }
  },
  logout() {
    wx.showModal({
      title: '确定要退出登录吗',
      success(res) {
        if (res.confirm) {
          wx.removeStorageSync(Varible.TOKEN_KEY)
          wx.navigateTo({
            url: '/pages/login/login'
          })
        }
      }
    })
  },
  goToOrderStats: function () {
    wx.navigateTo({
      url: '/pages/orderStats/orderStats'
    });
  },
  goToMyEvaluation: function () {
    wx.navigateTo({
      url: '/pages/myEvaluation/myEvaluation'
    });
  },
  goToMyTransport: function () {
    wx.navigateTo({
      url: '/pages/myTransport/myTransport'
    });
  },
  goToMyChild: function () {
    wx.navigateTo({
      url: '/pages/myChild/myChild'
    });
  },
  goToRequestHelp: function () {
    wx.navigateTo({
      url: '/pages/requestHelp/requestHelp'
    });
  },
  goToHelpAndCs: function () {
    wx.navigateTo({
      url: '/pages/helpAndCs/helpAndCs'
    });
  },
  onShow() {
    this.setData({
      avatarUrl: wx.getStorageSync(Varible.AVATAT_KEY),
      userName: wx.getStorageSync(Varible.NICKNAME_KEY)
    })
  },
});